//base
import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
//less
import './index.less'
import If from '../../../../../components/page-components/if'

class RecentlyTheLogin extends Component {
  componentWillMount() {
    //onLoad
  }

  componentDidMount() {
    //onready
  }

  componentWillUnmount() {
    //onUnload
  }

  componentWillReceiveProps(nextprops) {}

  delay(time = 0) {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve()
      }, time)
    })
  }

  changeCity = data => {
    this.props.onChangeCity({
      cityName: data.cityName,
      cityId: data.id
    })
  }

  render() {
    const { dataSource } = this.props
    return (
      <If visible={dataSource && dataSource.length}>
        <View className="RecentlyTheLogin_id76959">
          <View className="title">最近登录</View>
          <View className="list-wrap">
            {dataSource.map((data, index) => {
              return (
                <View
                  key={data.id || index}
                  className="list-single"
                  onClick={this.changeCity.bind(this, data)}
                >
                  {data.cityName}
                </View>
              )
            })}
          </View>
        </View>
      </If>
    )
  }
}

RecentlyTheLogin.defaultProps = {
  dataSource: []
}
export default RecentlyTheLogin
